intervals = 50;

min_x = 10000;
min_y = 10000;
max_x = -10000;
max_y = -10000;
load('meetup_small_1.mat');
for i = 1:length(event_lon_lat_new)
    x = event_lon_lat_new(i, 2);
    y = event_lon_lat_new(i, 3);
    if x < min_x
        min_x = x;
    elseif x > max_x
        max_x = x;
    end
    if y < min_y
        min_y = y;
    elseif y > max_y
        max_y = y;
    end
end
interval_x = min_x:(max_x-min_x)/intervals:max_x;
interval_y = min_y:(max_y-min_y)/intervals:max_y;

group_event_matrix = zeros(intervals, intervals, group_num);
for event = 1:500
    for group = 1:500
        if event_group_new(event, group) == 1
            x_index = 1;
            y_index = 1;
            for j = 1:intervals
                if x >= interval_x(j) && x <= interval_x(j+1)
                    x_index = j;
                    break;
                end
            end
            for j = 1:intervals
                if y >= interval_y(j) && y <= interval_y(j+1)
                    y_index = j;
                    break;
                end
            end
            group_event_matrix(x_index, y_index, group) = group_event_matrix(x_index, y_index, group)+1;
        end
    end
end
save('group_event_1.mat', 'interval_x', 'interval_y', 'group_event_matrix');

min_x = 10000;
min_y = 10000;
max_x = -10000;
max_y = -10000;
load('meetup_small_2.mat');
for i = 1:length(event_lon_lat_new)
    x = event_lon_lat_new(i, 2);
    y = event_lon_lat_new(i, 3);
    if x < min_x
        min_x = x;
    elseif x > max_x
        max_x = x;
    end
    if y < min_y
        min_y = y;
    elseif y > max_y
        max_y = y;
    end
end
interval_x = min_x:(max_x-min_x)/intervals:max_x;
interval_y = min_y:(max_y-min_y)/intervals:max_y;

group_event_matrix = zeros(intervals, intervals, user_num);
for event = 1:500
    for group = 1:500
        if event_group_new(event, group) == 1
            x_index = 1;
            y_index = 1;
            for j = 1:intervals
                if x >= interval_x(j) && x <= interval_x(j+1)
                    x_index = j;
                    break;
                end
            end
            for j = 1:intervals
                if y >= interval_y(j) && y <= interval_y(j+1)
                    y_index = j;
                    break;
                end
            end
            group_event_matrix(x_index, y_index, group) = group_event_matrix(x_index, y_index, group)+1;
        end
    end
end
save('group_event_2.mat', 'interval_x', 'interval_y', 'group_event_matrix');

min_x = 10000;
min_y = 10000;
max_x = -10000;
max_y = -10000;
load('meetup_small_3.mat');
for i = 1:length(event_lon_lat_new)
    x = event_lon_lat_new(i, 2);
    y = event_lon_lat_new(i, 3);
    if x < min_x
        min_x = x;
    elseif x > max_x
        max_x = x;
    end
    if y < min_y
        min_y = y;
    elseif y > max_y
        max_y = y;
    end
end
interval_x = min_x:(max_x-min_x)/intervals:max_x;
interval_y = min_y:(max_y-min_y)/intervals:max_y;

group_event_matrix = zeros(intervals, intervals, user_num);
for event = 1:500
    for group = 1:500
        if event_group_new(event, group) == 1
            x_index = 1;
            y_index = 1;
            for j = 1:intervals
                if x >= interval_x(j) && x <= interval_x(j+1)
                    x_index = j;
                    break;
                end
            end
            for j = 1:intervals
                if y >= interval_y(j) && y <= interval_y(j+1)
                    y_index = j;
                    break;
                end
            end
            group_event_matrix(x_index, y_index, group) = group_event_matrix(x_index, y_index, group)+1;
        end
    end
end
save('group_event_3.mat', 'interval_x', 'interval_y', 'group_event_matrix');